import { Injectable } from '@angular/core';
import { IVisitRecord, IVisitTask, IVisitTaskDetail, IVisitTheme } from '@model/visit';
import { ApiService } from '@core/net/api.service';
import { IHttpRes } from '@core/net/HttpResponse';

@Injectable({
	providedIn: 'root'
})
export class VisitService {

	constructor(
		private apiService: ApiService
	) { }


	/**
	 * 获取走访主题列表
	 * @param params 
	 * @returns 
	 */
	getVisitTheme(params: {
		page: number;
		limit: number;
		visitTitle: string;
	}): Promise<IHttpRes<{ totalCount: number, list: Array<IVisitTheme> }>> {
		return this.apiService.post('/info/tdatavisittitle/list', params).toPromise();
	}
	/**
	 * 走访主题编辑
	 * @param params 
	 * @returns 
	 */
	saveVisitTheme(param: IVisitTheme): Promise<IHttpRes<any>> {
		return this.apiService.post('/info/tdatavisittitle/save', param).toPromise();
	}
	/**
	 * 走访主题删除
	 * @param id 
	 * @returns 
	 */
	deleteVisitTheme(id: string): Promise<IHttpRes<any>> {
		return this.apiService.post('/info/tdatavisittitle/delete/' + id).toPromise();
	}

	/**
	 * 获取走访任务列表
	 * @param params 
	 * @returns 
	 */
	getVisitList(params: {
		page: number;
		limit: number;
		visitTitle: string;
	}): Promise<IHttpRes<{ totalCount: number, list: Array<IVisitTask> }>> {
		return this.apiService.post('/info/tdatagridervisit/list', params).toPromise();
	}

	/**
	 * 根据网格员获取走访列表
	 * @param params 
	 * @returns 
	 */
	getVisitByGrider(params: {
		page: number;
		limit: number;
		visitTitle: string;
	}): Promise<IHttpRes<{ totalCount: number, list: Array<IVisitTaskDetail> }>> {
		return this.apiService.post('/info/tdatagridervisit/visitByGrider', params).toPromise();
	}


	/**
	 * 获取走访列表
	 * @param params 
	 * @returns 
	 */
	getGriderVisit(params: {
		page: number;
		limit: number;
		visitTitle: string;
	}): Promise<IHttpRes<{ totalCount: number, list: Array<IVisitRecord> }>> {
		return this.apiService.post('/info/tdatagridervisit/visits', params).toPromise();
	}

	/**
	 * 走访处理
	 * @param params 
	 * @returns 
	 */
	saveVisit(params): Promise<IHttpRes<any>> {
		return this.apiService.post('/info/tdatagridervisit/save', params).toPromise();
	}
	/**
	 * 走访审核
	 * @param params 
	 * @returns 
	 */
	updateVisit(params): Promise<IHttpRes<any>> {
		return this.apiService.post('/info/tdatagridervisit/update', params).toPromise();
	}


	/**
	 * 走访审核记录列表
	 * @param id 
	 * @returns 
	 */
	getVisitTreatList(id): Promise<IHttpRes<any>> {
		return this.apiService.post(`/info/tdatagridervisit/treatList/${id}`).toPromise();
	}

	/**
	 * 走访任务提醒
	 * @param id 
	 * @returns 
	 */
	warmVisit(id): Promise<IHttpRes<any>> {
		return this.apiService.get(`/info/tdatagridervisit/visitWarm/${id}`).toPromise();
	}


}
